package com.ezzd.controller;

import com.ezzd.pojo.TbUser;
import com.ezzd.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @description tb_user
 * @author 被遗忘的湫
 * @date 2022-07-31
 */
@Controller
@RequestMapping(value = "/user")
@ResponseBody
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 新增
     * @author 被遗忘的湫
     * @date 2022/07/31
     **/
    @RequestMapping("/insert")
    public Object insert(TbUser tbUser){
        return userService.insert(tbUser);
    }

    /**
     * 刪除
     * @author 被遗忘的湫
     * @date 2022/07/31
     **/
    @RequestMapping("/delete/{id}")
    public Object delete(@PathVariable("id") int id){
        return userService.delete(id);
    }

    /**
     * 更新
     * @author 被遗忘的湫
     * @date 2022/07/31
     **/
    @RequestMapping("/update")
    public Object update(TbUser tbUser){
        return userService.update(tbUser);
    }

    /**
     * 查询 根据主键 id 查询
     * @author 被遗忘的湫
     * @date 2022/07/31
     **/
    @RequestMapping("/load/{id}")
    public Object load(@PathVariable("id") int id){
        return userService.load(id);
    }

    /**
     * 查询 分页查询
     * @author 被遗忘的湫
     * @date 2022/07/31
     **/
    @RequestMapping("/list")
    public Object pageList(@RequestParam(required = false, defaultValue = "1") int pageNum,
                           @RequestParam(required = false, defaultValue = "10") int pagesize) {
        return userService.pageList(pageNum, pagesize);
    }

    @RequestMapping("/query/{userName}/{password}/{roleName}")
    public Object queryUserAndRole(@PathVariable("userName") String userName,
                                   @PathVariable("password") String password,
                                   @PathVariable("roleName") String roleName
                                   ){
        return  userService.queryUserAndRole(userName,password,roleName);
    }


}